<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('财务支付宝流水列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <div class="row">
                            <ul>
                                <li>
                                    <label>交易号：</label>
                                    <input type="text" name="tradeNo"/>
                                </li>
                                <li>
                                    <label>订单号：</label>
                                    <input type="text" name="orderNo"/>
                                </li>
                                <li>
                                    <label>账单类型：</label>
                                    <select name="billType" th:with="type=${@dict.getType('bill_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                            </ul>
                        </div>
                        <div class="row">
                            <ul>
                            <li>
                                <label> 交易状态：</label>
                                <select name="tradeStatus" th:with="type=${@dict.getType('trade_status_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>真实收支：</label>
                                <select name="realIncomeExpenditureType" th:with="type=${@dict.getType('real_income_expenditure_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <li>
                                <label>财务用途：</label>
                                <select name="realFinanceType" th:with="type=${@dict.getType('real_finance_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                        </div>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:flow:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:flow:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:flow:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="$.table.importExcelAlipay()" shiro:hasPermission="system:flow:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
               <!-- <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:flow:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
                <a class="btn btn-primary" onclick="designDicType('134')" shiro:hasPermission="system:flow:designTradeType">
                    <i class="fa fa-sort-numeric-desc"></i> 设计收支类型
                </a>
                <a class="btn btn-warning" onclick="designDicType('135')" shiro:hasPermission="system:flow:designTradeType">
                    <i class="fa fa-cny"></i> 设计财务用途
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:flow:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:flow:remove')}]];
        var tradeTypeDatas = [[${@dict.getType('trade_type')}]];
        var tradeStatusDatas = [[${@dict.getType('trade_status_type')}]];
        var incomeExpenditureTypeDatas = [[${@dict.getType('income_expenditure_type')}]];
        var realIncomeExpenditureTypeDatas = [[${@dict.getType('finance_real_sz_type')}]];
        var realFinanceTypeDatas = [[${@dict.getType('real_finance_type')}]];
        var capitalStatusDatas = [[${@dict.getType('capital_status')}]];
        var billTypeDatas = [[${@dict.getType('bill_type')}]];
        var prefix = ctx + "system/flow";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "财务账单流水",
                showFooter: true,
                footerStyle: footerStyle,
                columns:
                [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'tradeNo',
                    title: '交易号',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }

                },
                {
                    field: 'orderNo',
                    title: '商家订单号',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'goodsName',
                    title: '商品',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                    {
                        field: 'realFinanceType',
                        title: '财务用途',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(realFinanceTypeDatas, value);
                        }
                    },
                {
                    field: 'tradePrice',
                    title: '交易金额(元)'
                 },

                    {
                        field: 'billType',
                        title: '账单类型',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(billTypeDatas, value);
                        }
                    },
                {
                    field: 'tradeType',
                    title: '交易类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(tradeTypeDatas, value);
                    }
                },
                {
                    field: 'counterparty',
                    title: '交易对方',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },

                {
                    field: 'tradeStatus',
                    title: '交易状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(tradeStatusDatas, value);
                    }
                },
                {
                    field: 'incomeExpenditureType',
                    title: '账单收支类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(incomeExpenditureTypeDatas, value);
                    },
                    footerFormatter:function (value) {
                        var tradePrice = 0;
                        for (var i in value) {
                            //支出
                            if(value[i].realIncomeExpenditureType==2){
                                tradePrice+=parseFloat(value[i].tradePrice);
                            }
                        }
                        return "总收入：" + tradePrice;
                    }
                },
                    {
                        field: 'realIncomeExpenditureType',
                        title: '真实收支类型',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(realIncomeExpenditureTypeDatas, value);
                        },
                        footerFormatter:function (value) {
                            var tradePrice = 0;
                            for (var i in value) {
                                //支出
                                if(value[i].realIncomeExpenditureType==1){
                                    tradePrice+=parseFloat(value[i].tradePrice);
                                }
                            }
                            return "总支出：" + tradePrice;
                        }
                    },
                    {
                        field: 'payTime',
                        title: '交易时间',
                        footerFormatter:function (value) {
                            var tradePrice = 0;
                            for (var i in value) {
                                //支出
                                if(value[i].realIncomeExpenditureType==1){
                                    tradePrice-=parseFloat(value[i].tradePrice);
                                }else if(value[i].realIncomeExpenditureType==2){
                                    tradePrice += parseFloat(value[i].tradePrice);
                                }

                            }
                            return "总金额：" + tradePrice;
                        }
                    },
/*
                {
                    field: 'belongUserName',
                    title: '所属人'
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function importTemplate(fileName) {
            window.location.href =  "/common/downloadExcel?fileName="+fileName;
        }

        /*字典列表-详细*/
        function designDicType(dictId) {
            var url = '/system/dict/detail/' + dictId;
            $.modal.openTab("字典数据", url);
        }

        function footerStyle(column) {
            return {
                tradePrice: {
                    css: { color: 'red', 'font-weight': 'normal' }
                }
            }[column.field]
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class=" form-horizontal m mt20 mb10" >
        <div class="col-xs-offset-1">
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-3 control-label">下载模板：</label>
                    <div class="col-sm-3">
                        <a onclick="importTemplate('alipay_record_excel.xlsx')" class="btn  btn-xs btn-danger"><i class="fa fa-file-excel-o"></i> 下载支付宝模板</a>
                    </div>
                    <div class="col-sm-3">
                        <a onclick="importTemplate('wechat_excel')" class="btn  btn-xs btn-danger"><i class="fa fa-file-excel-o"></i> 下载微信模板</a>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-3 control-label">导入数据：</label>
                    <div class="col-sm-5">
                        <input type="file" id="file" name="file"/>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-3 control-label">账单类型：</label>
                    <div class="col-sm-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('bill_type')}">
                            <input type="radio" th:id="${'billType_' + dict.dictCode}" name="billType" th:value="${dict.dictValue}" th:checked="${dict.default}">
                            <label th:for="${'billType_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group">
                    <label class="col-sm-3 control-label">交易账户：</label>
                    <div class="col-sm-8">
                        <input name="tradeAccount" id="tradeAccount" class="form-control"  type="text">
                    </div>
                </div>
            </div>
            <div class="row">
            <div class="form-group">
                <label class="col-sm-3 control-label">真实姓名：</label>
                <div class="col-sm-8">
                    <input name="tradeRealName" id="tradeRealName" class="form-control" type="text">
                </div>
            </div>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！支付宝和微信导出的账单是csv格式，请转换成支持的格式再导入。<h4>切记：千万不要直接改文件后缀名字！！！</h4>
            </font>
        </div>
    </form>

</script>
</html>